import request from "@/utils/request";
import type { RoleListResponse, SetRoleData, User, UserListResponse } from "./type";
enum API {
    USER_LIST_URL = "/admin/acl/user",
    USER_ADD_URL = "/admin/acl/user/save",
    USER_UPDATE_URL = "/admin/acl/user/update",
    GET_ROLE_LIST_URL = "/admin/acl/role/toAssign",
    SET_ROLE_URL = "/admin/acl/user/doAssignRole",
    DELETE_USER_URL = "/admin/acl/user/remove",
    DELETE_USER_BATCH_URL = "/admin/acl/user/batchRemove",
}

export const getUserList = (page: number, limit: number, searchValue: string) => request.get<any, UserListResponse>(API.USER_LIST_URL + `/${page}/${limit}?searchValue=${searchValue}`)
export const addorupdateUser = (data: User) => {
    if (data.id) {
        return request.put<any, any>(API.USER_UPDATE_URL, data)
    } else {
        return request.post<any, any>(API.USER_ADD_URL, data)
    }
}
export const getRoleList = (userId: number) => request.get<any, RoleListResponse>(API.GET_ROLE_LIST_URL + `/${userId}`)
export const setRole = (data:SetRoleData) => request.post<any, any>(API.SET_ROLE_URL, data)
export const deleteUser = (userId: number) => request.delete<any, any>(API.DELETE_USER_URL + `/${userId}`)
export const deleteUserBatch = (idList: number[]) => request.delete<any, any>(API.DELETE_USER_BATCH_URL, { data: idList })